<template>
	<view class="leave_body" style="padding-bottom:60rpx;">
		<view class="leaveapply_box">
			<view class="leave_title">
				请假人基本信息
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>学生姓名</span>
				<span class='leave_row_right'>{{name}}</span>
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>学生学号</span>
				<span class='leave_row_right'>{{id}}</span>
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>学生班级</span>
				<span class='leave_row_right'>{{classname}}</span>
			</view>
		</view>
		<view class="leaveapply_box">
			<view class="leave_title">
				请假时间
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>开始时间</span>
				<span class='leave_row_right'>{{starttime}}</span>
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>结束时间</span>
				<span class='leave_row_right'>{{endtime}}</span>
			</view>
			<view class="leave_row">
				<span class='leave_row_left'>总时长</span>
				<span class='leave_row_right'>{{hours}} 小时</span>
			</view>
		</view>
		<view class="leaveapply_box2">
			<view class="leave_title">
				请假详情
			</view>
				<textarea disabled='true' :value="reason"></textarea>
		</view>
		<view class="leaveapply_box2">
			<view class="leave_title">
				外出路线描述
			</view>
			<textarea disabled='true' :value="course"></textarea>
		</view>
		<view class="leaveapply_box2" v-if="imgpath!=''">
			<view class="leave_title">
				图片
			</view>
			<image :src="imgpath" mode="widthFix" v-if="imgpath!=''"></image>
		</view>
		<view class="leaveapply_box2" >
			<view class="leave_title">
				审批意见
			</view>
			<textarea v-model="fdyyj"></textarea>
			<button class="button_submit" v-if="hours<=72" @click="handleLeave('2')">批准请假</button>
			<button class="button_submit" v-if="hours>72" @click="handleLeave('4')">批准并提交至书记</button>
			<button class="button_submit" @click="handleLeave('3')">拒绝</button>
		</view>
	</view>
</template>

<script>
	// import imgHD from "@/pages/components/imgHD.vue"
	export default {
		data() {
			return {
				id: '',
				name: '',
				classname: '计算机应用2班',
				starttime: '8:00',
				endtime: '12:00',
				hours: '4',
				reason: '生病了',
				course: 'xxxxxx地铁站，xxxxxx医院，xxxxxxxxx餐厅，xxxxxxxx地铁站，xxxxxxxx公交车，返回学校',
				imgurl: [],
				imgshow: false,
				imgpath:'',
				leave_id: '',
				fdyyj: ''
			}
		},
		methods: {
			handleLeave(num) {
				console.log(this.id)
				if (typeof this.fdyyj == 'undefined' || this.fdyyj == null || this.fdyyj == '') {
					uni.showToast({
						title: '请输入意见',
						icon: "error",
						duration: 1000
					});
					return;
				}
				console.log(this.fdyyj)
				//同意请假
				uni.request({
					// url: '/api/appteacher/updateLeave',
					url: this.baseUrl+ "/appteacher/updateLeave?satoken="+uni.getStorageSync('satoken'),
					method: "POST",
					headers: {
						// "token": localStorage.getItem("token")
					},
					data: {
						leave_id: this.leave_id,
						fdyyj: this.fdyyj,
						shenpistatus: num
					},
					success: (res) => {
						console.log(res.data)
						if (res.data.code == 200) {
							//界面跳转（首页）
							/* this.$router.push({
								path: '/pages/TabBar/index/index'
							}); */
							
							uni.reLaunch({
								url: '/pages/TabBar/index/index',
							});		
							/* uni.navigateTo({
								url: '/pages/components/leaveList',
								success: function(e) {
								        var page = getCurrentPages().pop();
								        if (page == undefined || page == null) return;
								        page.onLoad();
								    }
							});	 */
						} else {
							uni.showToast({
								title: res.data.error,
								icon: "error",
								duration: 1000
							});
						}
					}
				})

			},

			open() {
				this.imgshow = true;
			},
			close() {
				this.imgshow = false;
			}

		},
		onLoad(options) {
			let _this=this
			console.log("detail..............")
			console.log(options.id)
			//提交数据请求接口
			uni.request({
				// url: '/api/appteacher/getLeaveDetails',
				url: this.baseUrl+ '/appteacher/getLeaveDetails',
				method: "POST",
				data: {
					leave_id: options.id
				},
				success: (res) => {
					_this.getData = res.data.result;
					_this.name = _this.getData.name
					_this.id = _this.getData.sno
					this.classname=_this.getData.class_name
					_this.starttime = _this.getData.begintime
					_this.endtime = _this.getData.endtime
					_this.hours = _this.getData.hours
					
					_this.reason = _this.getData.reason
					_this.course = _this.getData.description
					_this.imgurl = _this.getData.list
					_this.leave_id = _this.getData.leave_id
					if(_this.getData.imgpath)
						_this.imgpath = _this.baseUrl + "/upload/" +_this.getData.imgpath
				}
			})
		},
		components: {
			// imgHD
		}
	}
</script>

<style lang="scss">
	@import url(@/static/common.css);

	
</style>
